import { fileURLToPath, URL } from 'node:url'

import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    Components({
      resolvers: [
        // ant design 组件自动导入
        AntDesignVueResolver({
          importStyle: false,
        }),
      ],
      dirs: ['src/common/components'], // 搜索的组件目录
    }),
    AutoImport({
      imports: ['vue', '@vueuse/core'], // 自动导入的包
      dirs: ['src/common/composables', 'src/common/utils', 'src/common/stores', 'src/common/components'], // 自动导入的文件
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  css: {
    // 预处理器
    preprocessorOptions: {
      scss: {
        // 引入全局scss变量
        additionalData: `@import "@/assets/styles/variables.scss";`,
      },
    },
  },
  envPrefix: 'EDUC_', // 自定义环境变量前缀
})
1